﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace CrossLine
{
    class ReadStockFile
    {
        public static List<string> readStockFile(string  fileName)
        {
            if (File.Exists(fileName))
            {
                DateTime now = DateTime.Now;
                string sz = "sz";
                string sh = "sh";
                List<string> stocks = new List<string>();
                LogUtil.LogLine("开始时间：" + now.ToString());
                Stopwatch watch = new Stopwatch();
                watch.Start();

                int i = 0;
                StreamReader sr = new StreamReader(fileName, Encoding.UTF8);
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (Convert.ToInt32(line.Substring(0, 1)) < 6) stocks.Add(sz + line);
                    else stocks.Add(sh + line);
                    i++;
                }
                LogUtil.LogLine("股票数量:" + i);
                watch.Stop();
                double time = watch.ElapsedMilliseconds;
                LogUtil.LogLine("用时：" + time + " 毫秒");
                return stocks;
            }
            else
            {
                LogUtil.LogLine("文件不存在");
                return null;
            }
        }
    }
}
